home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr48
/
db2pas.zip
/
DB2PAS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-11
|
4KB
|
177 lines
PROGRAM translate;
{Code conversion utility by Vaden House, Dec 7, 1985.
This program is designed to take screen layouts written in
ADL (db II or III) and convert them to Turbo pascal code. I
used Quickcode to produce a number of I/O screens and
decided later to rewrite the program in Turbo so I thought I
would carry my screens along with me. The result is not
quite so fancy as something like Screen Sculpter but is much
more transparent and less likely to conflict with other code
you might write, beg, or borrow.Please note that this only
works with the type of dBASE commands found in the FMT
files.It will not do any fancy translation of other dBASE
commands. That, alas is beyond my meager talent.}
TYPE
anystr = STRING[255];
VAR
lineno : integer;
workline,
dbfile,
Tfile : anystr;
infile,
outfile : text;
ch : char;
I : integer;
PROCEDURE msg(s:anystr);
BEGIN
gotoxy(2,23);
write('':78);
gotoxy(2,23);
write(s);
END;
(* UpcaseStr converts a string to upper case *)
function UpcaseStr(S : AnyStr) : AnyStr;
var
P : Integer;
begin
for P := 1 to Length(S) do
S[P] := Upcase(S[P]);
UpcaseStr := S;
end;
FUNCTION Exist(FileN: AnyStr): boolean;
VAR F: FILE;
BEGIN
{$I-}
assign(F,FileN);
reset(F);
{$I+}
IF IOResult<>0
THEN Exist := false
ELSE Exist := true;
END;
PROCEDURE Getfilename(VAR Line: AnyStr);
BEGIN
WHILE NOT exist(line) DO
BEGIN
msg('Name of DB II file (include extension) :');
Line := '';
Read(line);
END;
END;
Procedure filter(line:anystr); {String delimiters must be ' '}
var
i:integer;
begin
For I:=1 To Length(line) Do
begin
If (line[I]='"') Then line[I]:='''';
End;
workline:=line;
end;
PROCEDURE convert(VAR line:anystr);
{this cryptic piece of gobledygook does all the real work}
VAR
x,y : anystr;
BEGIN
{get the x screen coordinate}
x := copy(line,3,pos(',',line)-3);
{get the y screen coordinate}
y := copy(line,pos(',',line)+1,pos('S',line)-(2+pos(',',line)));
{column 0 doesn't work so well in turbo}
IF y = '0'
THEN y := '1';
{get rid the db stuff-- delete line up to the start of the string constant}
delete(line,1,pos('SAY',line)+3);
{we only want to display string constants, send a blank line otherwise}
IF copy(line,1,1) <>''''
THEN BEGIN;
line := '';
exit;
END;
{add turbo's direct screen addressing command to the beginning of line}
insert('gotoxy(',line,1);
{reverse the x,y coordinates and add the write command}
insert(y + ',' + x + ');' + 'write(',line,8);
{add the terminating parentheses and semicolon}
line := line + ');';
END;
function rvson:char;
begin
rvson:=' ';
textcolor(0);
textbackground(7);
end;
function rvsoff:char;
begin
rvsoff:=' ';
textcolor(7);
textbackground(0);
end;
BEGIN
clrscr;
dbfile := '';
tfile := '';
getfilename(dbfile);
dbfile:=upcasestr(dbfile);
Tfile:=copy(dbfile,1,pos('.',dbfile))+'PAS';
if exist(Tfile) then
begin
repeat
msg('Name of Turbo file (include extension) :');
read(Tfile);
if exist(Tfile) then
begin
msg('File exists. Use another name.');
read(kbd,ch);
end;
until not exist(Tfile);
end;
Tfile:=upcasestr(Tfile);
clrscr;
gotoxy(15,12);write('Converting dBASE file ',rvson,dbfile,' ',rvsoff, 'to Turbo file ',rvson,Tfile,' ',rvsoff);
assign(infile,dbfile);
assign(outfile,tfile);
reset(infile);
rewrite(outfile);
writeln(outfile,'PROGRAM IO;');
writeln(outfile,'BEGIN');
writeln(outfile,' clrscr;');
lineno := 1;
WHILE NOT eof(infile) DO
BEGIN
readln(infile,workline);
filter(workline);
convert(workline);
gotoxy(30,15);writeln(' Converting line ',lineno);
if workline<>'' then
writeln(outfile,' ',workline);
lineno := lineno+1;
END;
writeln(outfile,'END.');
close(infile);
close(outfile);
msg(' Press any key to continue....');
read(kbd,ch);
END.